<template>
  <div class="box">
    <el-button
      type="success"
      size="small"
      icon="el-icon-edit"
      class="added"
      @click="added"
      >新增用户</el-button
    >

    <!-- 内容 -->
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      default-expand-all
      :tree-props="{ children: 'childs' }"
    >
      <el-table-column prop="title" label="标题" width="180">
        <template #default="{ row }">
          <i class="el-icon-folder"></i>
          <span>{{ row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="code" label="权限点代码" width="920">
      </el-table-column>
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            circle
            @click="handleEdit(scope.row)"
            icon="el-icon-edit"
          ></el-button>
          <el-button
            type="danger"
            plain
            circle
            @click="handleDelete(scope.row)"
            icon="el-icon-delete"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <MenuAdd ref="muenadd" :text="text"></MenuAdd>
    <!--
    <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            circle
            @click="handleEdit(scope.row)"
            icon="el-icon-edit"
            v-show="scope.row.username !=='超级管理员'"
          ></el-button>
          <el-button
            type="danger"
            plain
            circle
            @click="handleDelete(scope.row)"
            icon="el-icon-delete"
            v-show="scope.row.username !=='超级管理员'"
          ></el-button>
        </template>
      </el-table-column> -->
  </div>
</template>

<script>
import { list, remove, detail } from '@/api/base/menus.js'
import { simple } from '@/api/base/permissions.js'
import MenuAdd from '../components/menu-add.vue'
export default {
  components: {
    MenuAdd
  },
  data () {
    return {
      simpl: [],
      details: {},
      text: '',
      currentPage4: 1,
      defaultProps: {
        children: 'points',
        label: 'title'
      },
      fullscreenLoading: false,
      counts: 1,
      input: '',
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ]
    }
  },

  async created () {
    this.userLis()
  },

  methods: {
    // 修改数据
    async handleEdit (row) {
      const { data } = await detail(row)
      console.log(data)
      this.$refs.muenadd.formMenu = {
        id: data.id, // 父级Id
        pid: 0,
        is_point: data.is_point, // 是否权限点
        code: data.code, // 菜单代码
        title: data.title // 标题
      }
      this.text = '菜单'
      this.$refs.muenadd.dialogFormV()
    },

    // 添加用户
    async added () {
      this.$refs.muenadd.dialogFormV()
      this.text = '创建菜单'
      const data = await simple()
      this.$refs.muenadd.notPointDataList = data.data
    },
    async handleDelete (row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          remove(row)
          this.userLis()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 获取菜单数据的方法
    async userLis () {
      const data = await list()
      this.tableData = data.data
      this.counts = data.data.length
    },
    handleClick (row) {
      // console.log(row)
    },
    // 清空
    empty () {
      // this.input = ''
      // this.userLis()
    },
    // 搜索
    async search () {
      // const { data } = await list(this.data)
      // this.tableData = data.list.filter(item => item.username === this.input)
    }
  }
}
</script>

<style scoped lang="less">
.butt {
  margin: 20px;
  text-align: right;
  margin-right: 220px;
  padding-bottom: 20px;
}
.el-table {
  padding: 0 20px;
}
.added {
  margin-top: 20px;
  margin-left: 1180px;
}
.box {
  width: 1300px;
  // height: 600px;
  margin: 20px 20px;
  border-radius: 5px;
  background-color: #fff;
}
// .el-input {
//   width: 200px;
//   margin-top: 20px;
//   margin-left: 20px;
// }
// .el-row {
//   margin-top: -32px;
//   margin-left: 235px;
// }
</style>
